package com.locus.locus.server.dados;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.locus.locus.client.dados.BoxWrapper;
import com.locus.locus.client.dados.TweetWrapper;

@PersistenceCapable
public final class Box implements Wrappable<BoxWrapper> {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent
	private String nomeBox;
	@Persistent
	private List<Tweet> tweets;

	public Key getKey() {
		return key;
	}
	public void setKey(Key key) {
		this.key = key;
	}
	public String getNomeBox() {
		return nomeBox;
	}
	public void setNomeBox(String nomeBox) {
		this.nomeBox = nomeBox;
	}
	public List<Tweet> getTweets() {
		return tweets;
	}
	public void setTweets(List<Tweet> tweets) {
		this.tweets = tweets;
	}

	@Override
	public void deserializarRelacionamentos(PersistenceManager pm) {	}

	@Override
	public BoxWrapper gerarWrapper() {
		final BoxWrapper wrapper = new BoxWrapper();
		final ArrayList<TweetWrapper> tweets;
		
		if(this.tweets == null){
			tweets = new ArrayList<TweetWrapper>(0);
		}else{
			tweets = new ArrayList<TweetWrapper>(this.tweets.size());
			for(Tweet tweet:this.tweets){
				tweets.add(tweet.gerarWrapper());
			}
		}
		
		wrapper.setNomeBox(this.nomeBox);
		wrapper.setTweets(tweets);
		
		return wrapper;
	}
}
